package main

import "fmt"

/*
   创建结构体的四种方式
*/
func main() {
	demo4()
}

// 方式一：直接声明
func demo1() {
	var stu Student
	stu.Name = "Alice"
	stu.Age = 24
	fmt.Println(stu)
}

//方式二
func demo2() {
	var stu = Student{}
	stu.Name = "Alice"
	stu.Age = 24
	fmt.Println(stu)
}

//方式三
func demo3() {
	var stu *Student = new(Student)
	//(*stu).Name和stu.Name等价
	(*stu).Name = "Pete"
	stu.Name = "Alice"
	stu.Age = 25
	fmt.Println(*stu)
}

// 方式四
func demo4() {
	var stu1 *Student = &Student{}
	var stu2 *Student = &Student{Name: "Bob"}
	stu1.Name = "Alice"
	stu1.Age = 20
	stu2.Age = 24
	fmt.Println(*stu1)
	fmt.Println(*stu2)
}

type Student struct {
	Name string
	Age  int
}
